package hotel.base.oversea.utils;

import hotel.base.oversea.constant.enums.SwitchLableEnums;

import java.util.Random;

/**
 * @Author lmf
 * @Date 2020/6/29 10:56
 *  随机获取枚举的某个值
 **/
public class RandomEnums {
    private static int random=(int)(Math.random()*10);
    private static Random rand=new Random(random);

    /**
     * 随机获取枚举的某个值
     * @param tClass
     * @param <T>
     * @return
     */
    public static <T extends Enum<T>> T random(Class<T> tClass){
        T[] values=tClass.getEnumConstants();
        return values[rand.nextInt(values.length)];
    }

    /**
     * 测试案例
     * @param args
     */
    public static void main(String[] args){
        SwitchLableEnums code=RandomEnums.random(SwitchLableEnums.class);
        System.out.println(code.getCode());
    }



}
